package com.amit.Basic_Simple_Program;

import java.util.Scanner;

public class Mul_Matrics {

	public static void main(String[] args) {
		
		int c,d,m,n,p,q;
		int first[][];
		int second[][];
		int mul[][]=new int[10][10];
		int sum=0;
		
		System.out.println("Enter the number of rows and colums of first matrics");
		Scanner sc=new  Scanner(System.in);
		
		 m=sc.nextInt();
		 n=sc.nextInt();
		 
		 first=new int[m][n];
		
		
		 
		 System.out.println("Enter the element of first matrics");
		 
		 for(int i=0;i<m;i++)
		 {
			 for(int j=0;j<n;j++)
			 {
				 first[i][j]=sc.nextInt();
			 }
		 }
		 
		 System.out.println("Enter the number of rows and colums of first matrics");
			 sc=new  Scanner(System.in);
			
			 p=sc.nextInt();
			 q=sc.nextInt();
			 second=new int[p][q];
			 
		 
    System.out.println("Enter the element of second matrics");
		 
		 for(int i=0;i<p;i++)
		 {
			 for(int j=0;j<q;j++)
			 {
				 second[i][j]=sc.nextInt();
			 }
		 }
		 
		 
		 if(n!=p)
		 {
			 System.out.println("Multiplication of two matrics can not be done");
		 }
		 
		 else
		 {
		 
		 System.out.println("The multification of two matrics");
		 
		 for(int i=0;i<m;i++)
		 {
			 for(int j=0;j<q;j++)
			 {
				 for(int k=0;k<p;k++)
				 {
				 sum=sum+first[i][k]*second[k][j];
				 }
				 mul[i][j]=sum;
				 sum=0;
			 }
		 }
		 
		 
		 for(int i=0;i<m;i++)
		 {
			 for(int j=0;j<q;j++)
			 {
				 System.out.println(mul[i][j]);
			 }
		 }
		
		 }
		
		
		
		

	}

}
